package demo01;

import java.io.IOException;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class ValidateMapper extends Mapper<LongWritable, Text, NullWritable, Text> {
    private String splitter = "";

    @Override
    protected void setup(Mapper<LongWritable, Text, NullWritable, Text>.Context context)
            throws IOException, InterruptedException {
        splitter = context.getConfiguration().get("SPLITTER");
    }

    /**
     *
     * @param key
     * @param value
     * @param context
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, NullWritable, Text>.Context context)
            throws IOException, InterruptedException {
        String[] val = value.toString().split(splitter);
        //0,1008,0,35,3,77064,0,5,4,3,3,3,3,0,7,14,3,2,0,3,2,36,0,3
        context.write(NullWritable.get(), new Text(val[0] + splitter + val[2]));
    }
}
